#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e4 + 10;

int n;
priority_queue<LL, vector<LL>, greater<LL>> heap;

int main()
{
	cin >> n;
	for(int i = 1;i <= n;i ++)
	{
		int x; cin >> x;
		heap.push(x);
	}
	LL ans = 0;
	while(heap.size() > 1)
	{
		int x = heap.top(); heap.pop();
		int y = heap.top(); heap.pop();
		heap.push(x + y);
		ans += x + y;
	}
	cout << ans << endl;
	return 0;
}